{extend name=".././view/list.html" /}
{block name="jsset"}
<script language="Javascript">
  document.oncontextmenu=new Function("event.returnValue=false");
      document.onselectstart=new Function("event.returnValue=false");
    </script>
{/block}
{block name="nav"}
<span class="layui-breadcrumb">
  <a href="">成绩采集</a>
  <a href="">在线录入</a>
  <a><cite>学生列表</cite></a>
</span>
{/block}
{block name="search"}
<input type="hidden" id="kaoshi_id" name="kaoshi_id" value="{$list.set.src.kaoshi_id}">
{volist name="list.set.src.banji_id" id="vo"}
<input type="hidden" name="banji_id[]" value="{$vo}">
{/volist}
{volist name="list.set.src.subject_id" id="vo"}
<input type="hidden" name="subject_id[]" value="{$vo}">
{/volist}
{/block}
{block name="table"}
<table id="tabledemo" lay-filter="mytable" lay-size="sm"></table>
<div>
  <fieldset class="layui-elem-field">
  <legend>键盘操作提示</legend>
  <div class="layui-field-box">
    <span>Enter 换下一行 Shift+Eenter 移动到上一行</span><br>
  <span>Tab 移动移动到下一列 Shift+Tab 移动到下一列</span>
  </div>
</fieldset>
</div>
{/block}
{block name="myjs"}
<!-- 表格上面按钮模板 -->
<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
    <button class="layui-btn" lay-event="fanhui">
      <i class="layui-icon layui-icon-return"></i> 返回
    </button>
  </div>
</script>
<!-- 记录操作按钮模板 -->
<script type="text/html" id="barDemo">
</script>
<!-- 表格操作 -->
<script>
// 提交搜索条件后重载表格
layui.use(['table', 'form'], function() {
      var table = layui.table
      form = layui.form;

      // 设置列
      options.cols = [
        [ //表头
          { type: 'checkbox', fixed: 'left' },
          { type: 'numbers', fixed: 'left', title: '序号' },
          { field: 'school_jiancheng', title: '学校', width: 80, sort: true },
          { field: "xuehao", title: '学号', width: 100, sort: true },
          { field: "ban_title", title: '班级', width: 100, sort: true },
          { field: "student_xingming", title: '学生姓名', sort: true, width: 100 },
          { field: "sex", title: '性别', sort: true, width: 80 },
          {
            field: 'shengri',
            title: '生日 ',
            width: 100,
            sort: true,
            templet: function(d) {
              var mydata = d.shengri;
              var str = '';
              if (mydata != null) {
                y = mydata.indexOf('-');
                str = mydata.slice(0, y);
                m = mydata.indexOf('-', y + 1);
                str = str + '/ ' + mydata.slice(y + 1, m);
                d1 = mydata.indexOf('-', m + 1);
                str = str + '/ ' + '**';
              }
              return str;
            }
          },
        ]
      ];


      var xk = '<?php echo json_encode($list["set"]["subjectList"]);?>';
      xk = eval(decodeURIComponent(xk));

      $.each(xk, function(index, value) {
        options.cols[0].push({
          field: value.lieming,
          title: value.title,
          width: 80,
          sort: true,
          edit: 'text',
          templet: function(d) {
            var str = d[value.lieming];
            if (str == null) {
              str = '';
            }
            return str;
          }
        });
      });

      // 设置每页显示条数
      options.limit = 50;
      options.limits = [50, 70, 150];

      // 获取筛选条件并加载表格
      options.where = form.val("search");
      userTable = table.render(options); //获取数据并渲染


      //表头工具栏事件
      table.on('toolbar(mytable)', function(obj) {
        switch (obj.event) {
          case 'fanhui': // 查看
            window.location.href = "{$list.backurl}";
            break;
        };
      });

      //监听行工具条
      table.on('tool(mytable)', function(obj) {
        var data = obj.data; //获得当前行数据
        var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
        var tr = obj.tr; //获得当前行 tr 的DOM对象
        switch (layEvent) {
          case 'asdfasdf': // 查看
            window.location.href = "{$list.backurl}";
            console.log('aa');
            break;
        };
      });

      // 单元格编辑
      table.on('edit(mytable)', function(obj) {
        // 声明变量
        var newdefen = obj.value,
          colname = obj.field,
          rowdata = obj.data;
        colname = colname.replace('defen', '');

        // 修改服务器数据
        $.ajax({
          url: "/luru/index/update/" + rowdata.id,
          type: 'PUT',
          data: {
            "colname": colname,
            "newdefen": newdefen
          },
          success: function(result, objs) {
            if (result.val == 0 || result.code == 0) {
              layer.msg(result.msg, { icon: 5 });
            } else {
              obj.update({
                val: newdefen
              });
            }
          },
          error: function(result) {
            layer.msg('数据扔半道啦。', function() {});
          },
        });
      });


      /*
       *编辑数据表格，键盘快捷键方法。
       *可跳过无编辑属性的列
       *tab 右边一个单元格
       *shift + tab 左边一个单元格
       *enter 下一行的单元格
       *shift + enter 上一行的单元格
       */
      $(document).on('keydown keyup', '.layui-input',
          function(event) {
            var td = $(this).parent('td'),
              index = td.index(),
              tr = td.parent('tr'),
              isShift = $(document).data('shift'),
 isKeydown = (event.type == "keydown");

      switch (event.key) {
        case "Shift":
          $(document).data('shift', isKeydown);
          break;
        case "Tab":
          event.preventDefault();
          isKeydown && td[isShift ? 'prevAll' : 'nextAll']('[data-edit="text"]:first').click();
          break;
        case "Enter":
          isKeydown && tr[isShift ? 'prev' : 'next']().children('td').eq(index).click();
          break;
      }
    })

})

</script>
{/block}
